﻿window.addEventListener('load', function () {

    var left_items = document.querySelector(".left_item");
    var z = left_items.querySelector(".z");
    var table = left_items.offsetHeight;
    left_items.addEventListener('mouseenter', function () {
        //鼠标放到图片上面停止定时器
        clearInterval(timer);
        timer = null;// 清除定时器
    })

    left_items.addEventListener('mouseleave', function () {
        //当鼠标离开图片后几秒再次启动定时器
        timer = setInterval(function () {
            z.click();
        }, 3000);
    })

    var ul = left_items.querySelector('ul');

    //克隆第一章图片
    var firle = ul.children[0].cloneNode(true);
    ul.appendChild(firle);

    var num = 0;
    z.addEventListener('click', function () {
        if (num == ul.children.length - 1) {
            ul.style.left = 0;
            num = 0;
        }
        num++;
        anmate(ul, -num * table);
    })

    //轮播图自动播放
    var timer = setInterval(function () {
        z.click();
    }, 3000);
});